<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伪元素-清除浮动</title>

    <style>

        .clearfix:after {
            content: '';
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }

        .box {
            background-color: yellow;
            width: 500px;
        }

        .div1 {
            float: left;
            width: 200px;
            height: 100px;
            background-color: red;
        }

        .div2 {
            float: left;
            width: 200px;
            height: 100px;
            background-color: pink;
        }

    </style>

</head>
<body>

    <div class="box clearfix">   
        <div class="div1"></div>
        <div class="div2"></div>
    </div>
    
</body>
</html>